﻿package src.entity 
{
	/**
	* 
	* Reliability project
	* -----------------------
	* @author  Dmitrij Boycov
	* @mail    dmitry.boycov@gmail.com
	* @date    April 27, 2010
	* @version 1
	* 
	*/
	
	import src.computation.CEntity;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.events.Event;
	import flash.utils.Dictionary;
	
	/**
	 * Abstract class is parent for object of sheme.
	 * This class content generally property and methods
	 */
	public class Entity extends Sprite
	{
		//events
		public static const DOUBLE_CLICK_ON_ELEMENT:String = "DOUBLE_CLICK_ON_ELEMENT";
		public static const ENTITY_ON_DOWN = "ENTITY_ON_DOWN";
		public static const ENTITY_ON_UP = "ENTITY_ON_UP";
		// for identification into parent scheme
		public static const TYPE:String = "ENTITY";		
		public var id:Number;
		public var idBD:Number;
		public var nameElement:String;
		public var description:String;
		//
		protected var illuminateObj:Sprite;// = new Sprite(); 
		protected var indent:Number = 5;
		
		public function Entity(){			
		}
		
		// seters
		public function setId(id:Number):void {
			this.id = id;
		}
		public function setIDBD(id:Number):void {
			this.idBD = id;			
		}
		public function setName(name:String):void {
			this.nameElement = name;
		}
		public function setDescription(desc:String):void {
			this.description = desc;
		}
		// geters
		public function getType():String{
			return Entity.TYPE;
		}
		public function getName():String {
			return this.nameElement;
		}
		public function getDescription():String {
			return this.description;
		}
		public function getId():Number {
			return this.id;
		}
		////
		public function doActionOnDown():void {
			this.startDrag();
		}
		
		public function doActionOnUp():void {			
			this.stopDrag();
		}		
		// fire events
		protected function onDoubleClick(event:MouseEvent) {
			dispatchEvent(new Event(Entity.DOUBLE_CLICK_ON_ELEMENT));
		}
		
		protected function onDown(event:MouseEvent):void {
			dispatchEvent(new Event(Entity.ENTITY_ON_DOWN));	
		}
		
		protected function onUp(event:MouseEvent):void {			
			dispatchEvent(new Event(Entity.ENTITY_ON_UP));		
		}
		///////
		public function inactive():void {			
			if (this.illuminateObj != null) {
				if (this.contains(this.illuminateObj)) {								
					this.removeChild(this.illuminateObj);
				}
			}
		}
		
		protected function baseParametersToDict() {
			var cEnt:CEntity = new CEntity();			
			cEnt.id = this.id;
		//	cEnt.idBD = this.idBD;
			cEnt.name = this.nameElement;
			cEnt.description = this.description;
		//	cEnt.x = this.x;
		//	cEnt.y = this.y;			
			return cEnt;		
		}
		
		public function getDictDesc(){			
			return this.baseParametersToDict();
		}
	}
	
}